package com.canaan.business.controller.pc.basic;

import java.util.List;

import com.canaan.business.common.enums.basic.ContainerStatusEnum;
import com.canaan.business.common.enums.basic.ContainerTypeEnum;
import com.canaan.business.domain.basic.Container;
import com.canaan.business.service.basic.IContainerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * WMS 容器Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@Api(tags = "WMS 容器")
@RestController
@RequestMapping("/basic/container")
public class ContainerController extends BaseController {
    @Resource
    private IContainerService containerService;

    /**
     * 查询WMS 容器列表
     */
    @ApiOperation(value = "查询WMS 容器列表")
    @GetMapping("/list")
    public TableDataInfo list(Container container) {
        startPage();
        List<Container> list = containerService.selectContainerList(container);
        return getDataTable(list);
    }

    /**
     * 导出WMS 容器列表
     */
    @ApiOperation(value = "导出WMS 容器列表")
    @Log(title = "WMS 容器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Container container) {
        List<Container> list = containerService.selectContainerList(container);
        list.stream().forEach(e->{
             e.setContainerType(ContainerTypeEnum.getMessageByCode(e.getContainerType()));
             e.setStatus(ContainerStatusEnum.getMessageByCode(e.getStatus()));
        });
        ExcelUtil<Container> util = new ExcelUtil<Container>(Container.class);
        util.exportExcel(response, list, "WMS 容器数据");
    }

    /**
     * 获取WMS 容器详细信息
     */
    @ApiOperation(value = "获取WMS 容器详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(containerService.selectContainerById(id));
    }

    /**
     * 新增WMS 容器
     */
    @ApiOperation(value = "新增WMS 容器")
    @Log(title = "WMS 容器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Container container) {
        return toAjax(containerService.insertContainer(container));
    }

    /**
     * 修改WMS 容器
     */
    @ApiOperation(value = "修改WMS 容器")
    @Log(title = "WMS 容器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Container container) {
        return toAjax(containerService.updateContainer(container));
    }

    /**
     * 删除WMS 容器
     */
    @ApiOperation(value = "删除WMS 容器")
    @Log(title = "WMS 容器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(containerService.deleteContainerByIds(ids));
    }


    /**
     * 根据容器编号查询容器信息、已绑定的条码列表
     */
    @ApiOperation(value = "根据容器编号查询容器信息、已绑定的条码列表")
    @GetMapping(value = "/loadByNo/{no}")
    public AjaxResult selectContainerByNo(@PathVariable("no") String no) {
        return success(containerService.selectContainerByNo(no));
    }

}
